# 反射方法
# setattr(obj, key, value)
# hasattr(obj, key)
# delattr(obj, key)
# getattr(obj, key)

class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def run(self):
        print("这是绑定给对象的绑定方法")

    @classmethod
    def eat(cls):
        print("这是绑定给对象的类方法")

    @staticmethod
    def sleep():
        print("这是绑定给对象的静态方法")


student = Student("小王", 18)
# hasattr(obj,name) 判断对象中是否有指定的属性
print(hasattr(student, "name"))
print(hasattr(student, "gender"))

# getattr(obj,name) 获取对象中指定的属性
print(getattr(student, "name"))
print(getattr(student, "gender", "无此属性"))

# setattr(obj,name,value) 设置对象中指定的属性
setattr(student, "name", '12')
print(student.__dict__)

# delattr(obj,name) 删除对象中指定的属性
delattr(student, "name")
print(student.__dict__)
